import * as echarts from 'echarts';
import { onUnmounted } from 'vue';
import type { EChartsOption } from 'echarts';

export default function useEcart(divEl: any) {
	const echartInstance = echarts.init(divEl, 'light', { renderer: 'svg' });

	onUnmounted(() => {
		echartInstance.dispose(); //销毁实例
	});

	//   为了以后方便使用hooks
	const setOption = (option: EChartsOption) => {
		echartInstance.setOption(option);
	};

	const resizeEchart = () => {
		echartInstance.resize();
	};

	return {
		echartInstance,
		setOption,
		resizeEchart,
	};
}
